package com.yishun.springboot.service;

import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.Runner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.yishun.springboot.mapper.GwsPushDataMapper;
import com.yishun.springboot.pojo.GwsPushData;

import lombok.extern.slf4j.Slf4j;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * 上传工务署实名制-员工
 *
 * @author XiaoHuang
 * @date 2021年5月11日上午9:23:00
 */

@Slf4j
@Service
@Component
public class GongWuSuTimedUploadCWSPersonnelBaseInfoService {

	@Autowired
	GongWuSuUploadCWSService gongWuSuUploadCWSService;

	@Autowired
	GwsPushDataMapper gwsPushDataMapper;

	// 定时上传员工
	@Async(value = "asyncExecutor")
	@Scheduled(fixedRate = 4 * 60 * 60 * 1000)
	public void uploadPersonnelPassageData() throws NoSuchAlgorithmException, ParseException {
		List<GwsPushData> gpdList = gwsPushDataMapper.selectAllRecord();
		GwsPushData gpd = null;
		String result = "";

		String gwsProjectCode = null;
		Integer yzwProjectCode = null;
		String projectName = null;
		for (int i = 0; i < gpdList.size(); i++) {
			gpd = gpdList.get(i);
			gwsProjectCode = gpd.getGwsProjectCode();
			yzwProjectCode = gpd.getYzwProjectCode();
			projectName = gpd.getProjectName();
			if (gpd == null || gpd.getGwsProjectCode().equals("") || !gpd.getPushDataWorker())
				continue;
			// log.info("------------定时上传员工至工务署------------开始(" +
			// gpd.getProjectName() + ")。");
			result = gongWuSuUploadCWSService.uploadPersonnelBaseInfo(gwsProjectCode, yzwProjectCode, projectName);// 上传人员
			// log.info("*************上传员工至工务署---------------" + result + "。");
		}
	}
}
